#include "pch.h"
#include "MeshReconstruction.h"
#include "Common.h"
using namespace AutomatedSurfaceReconstruction;

CGALMeshType CScaleSpaceMeshReconstruction::reconstrcut()
{

	Reconstruction Reconstructor(m_PointCloud.points().begin(), m_PointCloud.points().end());
	Reconstructor.increase_scale<Smoother>(m_ScaleSpaceDepth);
	Reconstructor.reconstruct_surface(Mesher(m_MaxFacetLength));

	CGALMeshType Mesh;
	for (CGALPointSetType::iterator Iter = m_PointCloud.begin(); Iter != m_PointCloud.end(); ++Iter)
		Mesh.add_vertex(CGAL::Simple_cartesian<double>::Point_3(m_PointCloud.point(*Iter).x(), m_PointCloud.point(*Iter).y(), m_PointCloud.point(*Iter).z()));
	for (Reconstruction::Facet_iterator Iter = Reconstructor.facets_begin();
		Iter != Reconstructor.facets_end(); ++Iter)
	{
		CGALMeshType::Vertex_index U((*Iter)[0]);
		CGALMeshType::Vertex_index V((*Iter)[1]);
		CGALMeshType::Vertex_index W((*Iter)[2]);
		Mesh.add_face(U, V, W);
	}

	return Mesh;
}
